package com.sxt.bus.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sxt.bus.constast.BUSConstast;
import com.sxt.bus.service.CheckService;
import com.sxt.bus.vo.CheckVo;
import com.sxt.sys.utils.DataGridView;
import com.sxt.sys.utils.RandomUtils;
import com.sxt.sys.utils.WebUtils;

@Controller
@RequestMapping("check")
public class CheckController {
	@Autowired
	private CheckService checkService;
	
	//跳转
    @RequestMapping("toCheckCarManager")
	public String toCheckCarManager(){
		return "business/checkCarManager";
		
	}
     
    //根据出租单号加载页面默认数据
    @RequestMapping("loadCheckFormMsg")
    @ResponseBody
    public Map<String,Object> loadCheckFormMsg(CheckVo checkVo){
    	Map<String,Object> map=this.checkService.checkRentCarCustomer(checkVo.getRentid());
    	checkVo.setCheckdate(new Date());
		checkVo.setOpername(WebUtils.getCurrentUser().getRealname());
		checkVo.setCheckid(RandomUtils.createRandomStringUsePreFix(BUSConstast.CHECK_ID_PREFIX));
		map.put("check", checkVo);
		return map;
    	
    }
    //添加
    @RequestMapping("addCheck")
    @ResponseBody
    public Map<String,Object> addCheck(CheckVo checkVo){
    	Map<String,Object> map=new HashMap<String, Object>();
    	try {
    		checkService.addCheck(checkVo);
			map.put("msg", "保存成功");
		} catch (Exception e) {
			e.printStackTrace();
			map.put("msg", "保存失败");
		}
    	
		return map;
    	
    }
    
    
    //------------------------------
    @RequestMapping("toCheckManager")
   	public String toCheckManager(){
   		return "business/checkManager";
   		
   	}
    
    @RequestMapping("loadAllCheck")
    @ResponseBody
    public DataGridView loadAllCheck(CheckVo checkVo){
		return checkService.queryAllCheck(checkVo);
    	
    }
    //修改
    @RequestMapping("updateCheck")
    @ResponseBody
    public Map<String,Object> updateCheck(CheckVo checkVo){
    	Map<String,Object> map=new HashMap<String, Object>();
    	try {
    		checkService.updateCheck(checkVo);
			map.put("msg", "保存成功");
		} catch (Exception e) {
			e.printStackTrace();
			map.put("msg", "保存失败");
		}
    	
		return map;
    	
    }
}
